package com.player.dao;

public class DAOLocator {

	private static PlayerDAO playerDAO;
	private static GameDAO gameDAO;
	private static RankingDAO rankingDAO;

	public static void init() {
		playerDAO = new PlayerDAO();
		gameDAO = new GameDAO();
		rankingDAO = new RankingDAO();
	}

	public static PlayerDAO getPlayerDAO() {
		return playerDAO;
	}

	public static GameDAO getGameDAO() {
		return gameDAO;
	}

	public static RankingDAO getRankingDAO() {
		return rankingDAO;
	}

	/**
	 * TESTING
	 */
	public static void injectDAOMocks(DAO... daoMocks) {
		for (DAO daoMock : daoMocks) {
			if (daoMock instanceof PlayerDAO) {
				playerDAO = (PlayerDAO) daoMock;
			} else if (daoMock instanceof RankingDAO) {
				rankingDAO = (RankingDAO) daoMock;
			} else if (daoMock instanceof GameDAO) {
				gameDAO = (GameDAO) daoMock;
			} else {
				throw new IllegalArgumentException("No injection mechanism implemented for " + daoMock.getClass());
			}
		}
	}
}
